package com.authorization.pojo;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * @author chengyadong
 * @date 2023/11/30 13:42
 * @description 用户实体类 必须实现UserDetails接口
 * @JsonIgnoreProperties 作用是json序列化时将java bean中的一些属性忽略掉，序列化和反序列化都受影响  注意userName和passWord不能剔除，其需要序列化
 */
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "@class")
@JsonIgnoreProperties({"authorities","enabled","password","username","credentialsNonExpired",
		"accountNonLocked","accountNonExpired"})
public class UserInfo implements UserDetails {
	public String userName;
	public String passWord;

	@Override
	public Collection<? extends GrantedAuthority> getAuthorities() {
		List<GrantedAuthority> grantedAuthorities = new ArrayList<>();
		grantedAuthorities.add(new SimpleGrantedAuthority("test"));
		return grantedAuthorities;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public void setPassWord(String passWord) {
		this.passWord = passWord;
	}

	@Override
	public String getPassword() {
		return passWord;
	}

	@Override
	public String getUsername() {
		return userName;
	}

	// 指示用户的帐户是否已过期。无法对过期的帐户进行身份验证。
	@Override
	public boolean isAccountNonExpired() {
		return true;
	}

	//用户是否锁定，如果为false则代表用户被锁
	@Override
	public boolean isAccountNonLocked() {
		return true;
	}

	//用户凭证是否过期
	@Override
	public boolean isCredentialsNonExpired() {
		return true;
	}

	//指示用户是启用还是禁用。无法对禁用的用户进行身份验证。
	@Override
	public boolean isEnabled() {
		return true;
	}

}
